package com.smile.serverview;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.plaf.basic.BasicTextFieldUI;
import javax.swing.text.JTextComponent;

public class MyTextField extends BasicTextFieldUI {

	private JComponent jc;

	@Override
	public void installUI(JComponent c) {
		super.installUI(c);
		this.jc = c;
		
		JTextComponent text = (JTextComponent) c;
		text.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
	}

	@Override
	protected void paintBackground(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		
		JTextComponent text = (JTextComponent) jc;
		if(text.isEditable()){
			g2d.setColor(Color.WHITE);
		} else {
			g2d.setColor(new Color(238, 238, 238));
		}
		g2d.fillRoundRect(0, 0, jc.getWidth(), jc.getHeight(), 5, 5);
		g2d.setColor(new Color(136, 136, 136));
		g2d.drawRoundRect(0, 0, jc.getWidth() - 1, jc.getHeight() - 1, 5, 5);
	}

}
